import { createRouter, createWebHistory } from 'vue-router'
import type { RouteLocationNormalized, RouteLocationNormalizedLoaded } from 'vue-router'
import routes from './router.js'

const scrollBehavior = (to: RouteLocationNormalized, from: RouteLocationNormalizedLoaded, savedPosition: any) => {
  // savedPosition 点击浏览器的前进后退按钮的时候触发的行为
  if(savedPosition) return savedPosition
  return { left: 0, top: 0 }
}

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes,
  scrollBehavior
})

export default router
